package com.cssnj.portal.service.common;

import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.domain.exception.BaseException;
import io.predictech.framework.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Auther: yangxi
 * @Date: 2018/10/16 09:49
 * @Description:
 */
@Service("portalService")
public class PortalService  extends BaseService {

    //国税数据源
    @Qualifier("secondJdbcTemplate")
    @Autowired
    private JdbcTemplate secondJdbcTemplate;

    //地税数据源
    @Qualifier("thirdJdbcTemplate")
    @Autowired
    private JdbcTemplate thirdJdbcTemplate;

    @Override
    protected JsonResponse invokingService(JsonRequest jsonRequest) throws SQLException, BaseException {
        if("getSwjgList".equals(jsonRequest.getHandleCode())){
            return  getSwjgList(jsonRequest);
        }
        return null;
    }

    protected JsonResponse getSwjgList(JsonRequest jsonRequest) {

        JsonResponse jsonResponse = new JsonResponse();
        String sfJgjcDm = (String) jsonRequest.getReqData().get("sfJgjcDm");
        String sjswjg_dm = (String) jsonRequest.getReqData().get("cxjgdm");
        List<Object> params = new ArrayList<Object>();
        params.add(sfJgjcDm);
        params.add(sjswjg_dm);
        JdbcTemplate queryJdbcTemplate = secondJdbcTemplate;
        if (sjswjg_dm.startsWith("2")) {//地税
            queryJdbcTemplate = thirdJdbcTemplate;
        }
        List<Map<String, Object>> jgList = queryDao.queryForList(queryJdbcTemplate, "SELECT SWJG_DM ,REPLACE(SWJGJC,'国家税务总局','') SWJGJC\n" +
                "  FROM HX_DM_ZDY.DM_GY_SWJG Z\n" +
                " WHERE Z.JGJC_DM = ?\n" +
                "   AND Z.SWJGBZ = '0'\n" +
                "   AND Z.SJSWJG_DM = ?\n" +
                "   AND ZN_DM = '01'\n" +
                "   AND XYBZ = 'Y'\n" +
                " ORDER BY SWJG_DM ASC", params);
        jsonResponse.getRepData().put("jgList",jgList);

        return jsonResponse;

    }
    
    
    
}
